#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<queue>
#include<iostream>
using namespace std;
queue<int>x,y,z,ans;
int a,b,c,n;
bool g[101][101][101];//用于判重
bool flag=false;
int main()
{
    scanf("%d%d%d%d",&a,&b,&c,&n);
    if(a<n)//如果油量起始值小于目标值，当然不可能
    {
        cout<<"NO ANSWER!";
        return 0;
    }
    x.push(a);y.push(0);z.push(0);ans.push(0);//存入
    do//用do-while，那么至少会做一次，恰好也处理了初始状态等于目标状态的情况
    {
        int x1=x.front();
        int y1=y.front();
        int z1=z.front();
        int t=ans.front();
        if(x1==n||y1==n||z1==n)
        {
            flag=true;
            break;
        }//如果出现了目标状态，跳出循环
        if(x1>0)//如果1有油，就枚举1倒油的几种情况
        {
            if(g[x1-min(x1,b-y1)][y1+min(x1,b-y1)][z1]==0/*这个状态如果没有到过*/&&b-y1>0/*2可以倒出y1体积的油*/)
            {
                g[x1-min(x1,b-y1)][y1+min(x1,b-y1)][z1]=1;
                x.push(x1-min(x1,b-y1));
                y.push(y1+min(x1,b-y1));
                z.push(z1);//存入
                ans.push(t+1);//存步
            }
            //倒1->2
            if(g[x1-min(x1,c-z1)][y1][z1+min(x1,c-z1)]==0&&c-z1>0)
            {
                g[x1-min(x1,c-z1)][y1][z1+min(x1,c-z1)]=1;
                x.push(x1-min(x1,c-z1));
                y.push(y1);
                z.push(z1+min(x1,c-z1));
                ans.push(t+1);
            }//倒1->3
            if(g[0][y1][z1]==0)
            {
                g[0][y1][z1]=1;
                x.push(0);
                y.push(y1);
                z.push(z1);
                ans.push(t+1);
            }//倒空
        }
        if(y1>0)
        {
            if(g[x1][y1-min(y1,c-z1)][z1+min(y1,c-z1)]==0&&c-z1>0)
            {
                g[x1][y1-min(y1,c-z1)][z1+min(y1,c-z1)]=1;
                x.push(x1);
                y.push(y1-min(y1,c-z1));
                z.push(z1+min(y1,c-z1));
                ans.push(t+1);
            }//2->3
            if(g[x1+min(y1,a-x1)][y1-min(y1,a-x1)][z1]==0&&a-x1>0)
            {
                g[x1+min(y1,a-x1)][y1-min(y1,a-x1)][z1]=1;
                x.push(x1+min(y1,a-x1));
                y.push(y1-min(y1,a-x1));
                z.push(z1);
                ans.push(t+1);
            }//2->1
            if(g[x1][0][z1]==0)
            {
                g[x1][0][z1]=1;
                x.push(x1);
                y.push(0);
                z.push(z1);
                ans.push(t+1);
            }//倒完
        }
        if(z1>0)
        {
            if(g[x1][y1+min(z1,b-y1)][z1-min(z1,b-y1)]==0&&b-y1>0)
            {
                g[x1][y1+min(z1,b-y1)][z1-min(z1,b-y1)]=1;
                x.push(x1);
                y.push(y1+min(z1,b-y1));
                z.push(z1-min(z1,b-y1));
                ans.push(t+1);
            }//3->1
            if(g[x1+min(z1,a-x1)][y1][z1-min(z1,a-x1)]==0&&a-x1>0)
            {
                g[x1+min(z1,a-x1)][y1][z1-min(z1,a-x1)]=1;
                x.push(x1+min(z1,a-x1));
                y.push(y1);
                z.push(z1-min(z1,a-x1));
                ans.push(t+1);
            }//3->2
            if(g[x1][y1][0]==0)
            {
                g[x1][y1][0]=1;
                x.push(x1);
                y.push(y1);
                z.push(0);
                ans.push(t+1);
            }//倒完不要了
        }
        ans.pop();
        x.pop();
        y.pop();
        z.pop();
    }while(!x.empty());//状态没有枚举完
    if(flag==true)
        printf("%d",ans.front());
    else
        cout<<"NO ANSWER!";
    return 0;
}